﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Mail;
using System.Net.Mail;

public partial class Views_module_lostpassword : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        try
        {
            CustomerBus cusBus = new CustomerBus();
            Customer cus = new Customer();
            SendMail send = new SendMail();
            cus = cusBus.getCustomerByEmail(txtEmail.Text.Trim());

            string to = txtEmail.Text.Trim();
            string from = "teamcodeblock@gmail.com";
            string subject = "From Test.com - Password recover";
            string body = @"
            <htm>l
                <body>
                    <Table>
                        <tr>
                            <td>Hi, we're <a href='localhost/ofd'>Test SHOP</a></td>
                        </tr>
                        <tr>
                            <td>Your account has recovered:.</td>
                        </tr>
                        <tr>
                            <td>Email: " + cus.Email + @"</td>
                        </tr>
                        <tr>
                            <td>Password: " + cus.Password + @"</td>
                        </tr>
                    </Table>
                </body>
            </html>
            <html>
                <body>

                </body>
            </html>"
                +
            @"<html>
                <body>
                    <Table>
                        <tr>
                            <td> 
                            </td>
                        </tr>
                        <tr>
                            <td>
                                NOTE: This is an automated mail. Please, do not reply.
                            </td>
                        </tr>" +
                    "<tr><td> </td></tr><tr><td>Regards,</td></tr><tr><td>Thanks for use our service</td></tr>                </table></body></html>";

            if (send.Send_Mail(to, subject, body, true) != 0)
            {
                ScriptManager.RegisterStartupScript(this, typeof(Page), "test.com", "<script>alert('Password has sent to you. Let check your email...')</script>", false);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, typeof(Page), "Test.com", "<script>alert('Your email not exist in our system, or authenticated by proxy of server')</script>", false);
            }
        }
        catch (SmtpException ex)
        {
            Response.Write(ex.Message);
            ScriptManager.RegisterStartupScript(this, typeof(Page), "Test", "<script>alert('Your email not exist in our system, or authenticated by proxy of server')</script>", false);
        }


    }
 
}